package com.godz.frontData.index;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.godz.mapper.indexTwMapper;
import com.godz.pojo.indexTw;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//打字机动画
@RestController
public class twData {
    final
    indexTwMapper indexTwMapper;

    public twData(indexTwMapper indexTwMapper) {
        this.indexTwMapper = indexTwMapper;
    }
    //查询全部的打字机
    @GetMapping("/index/get/indexTw")
    public List<indexTw> getTw() {
        return indexTwMapper.queryAllTw();
    }
    //查询单个的打字机
    @GetMapping("/index/get/indexTw/{intId}")
    public indexTw getOneTw(@PathVariable("intId") Integer integer) {
        return indexTwMapper.selectOne(
                new QueryWrapper<indexTw>().eq("id", integer)
        );
    }
    //增加一条打字机
    @PostMapping("/index/post/addTw")
    public String addTw(@RequestBody indexTw tw) {
        indexTwMapper.insert(tw);
        return "insert OK";
    }
    //修改一条打字机
    @PostMapping("/index/post/editTw")
    public String editTw(@RequestBody indexTw tw) {
        QueryWrapper<indexTw> wrapper = new QueryWrapper<>();
        wrapper.eq("id", tw.getId());

        indexTw indexTw1 = new indexTw();
        indexTw1.setTwText(tw.getTwText());

        indexTwMapper.update(indexTw1, wrapper);
        return "Update OK";
    }
    //删除一条打字机
    @GetMapping("/index/get/deleteTw/{tId}")
    public String deleteTw(@PathVariable("tId") Integer integer) {
        indexTwMapper.deleteById(integer);
        return "Delete Ok";
    }

}
